package com.viu.technology.service.product;

import com.github.pagehelper.PageInfo;
import com.viu.technology.dao.product.ProductDao;
import com.viu.technology.po.Product;
import com.viu.technology.util.GenerateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductDao productDao;

    @Transactional
    @Override
    public int enteringProduct(Product product) {

        product.setProductId(GenerateUtil.generateUUID());
        product.setProductType(1);
        product.setProductStatus(1);

        int pResult = productDao.insertProduct(product);
        int sResult = productDao.insertProductStatis(GenerateUtil.generateUUID());

        if (pResult > 0 && sResult > 0) {
            return 1;
        }

        return 0;
    }

    @Override
    public PageInfo getAllProductWithPage() {
        return productDao.selectAllProductWithPage();
    }

}
